<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<div class="board_contents">
	<h1>ScheduleWeek</h1>
		<ul class="token">	
			<li><img src="resources/images/work_title.jpg"/>업무시작일</li>
			<li><img src="resources/images/work_title_end.jpg"/>업무종료일</li>
			<li><img src="resources/images/schedule_title.jpg"/>개인 일정</li>
		</ul>
		<input type="button" class="btn" style="float: left;" onclick="get_scheduleWeek(${calendar.endWeekYear}, ${calendar.endWeekMonth - 1},${calendar.endWeekDay}, false)"value="이전" /> 
		<div id="schedule_date">${calendar.startWeekYear }년 ${calendar.startWeekMonth + 1 } 월 ${calendar.weekList[0].week_of_month-1 } 주차</div>
		<input type="button" class="btn" id="schedule_margin_week" onclick="get_scheduleWeek(${calendar.endWeekYear}, ${calendar.endWeekMonth - 1},${calendar.endWeekDay}, true)"value="이후" />
		<input type="button" class="btn" value="월간" onclick="employee_schedule()"/>
		<input type="button" class="btn" style="width: 120px;" value="개인 일정 리스트" onclick="schedule_list(${emp.empNo})" >
		<input type="button" id="create-user" class="btn" style="width: 100px;  float:inherit;" value="개인 일정 추가" > <!-- onclick="schedule_add(${emp.empNo})" -->
	<div id="schedule_list">
		<div id="dialog-form">
		    <ul>
			    <li>>일&nbsp;&nbsp;&nbsp;정<input type="text" name="title" id="title" /></li>
			    <li>>시작일<input type="text" name="startDate" id="startDate"  /></li>
			    <li>>마감일<input type="text" name="endDate" id="endDate"/></li>
			    <li><textarea name="contents" id="contents"></textarea></li>
		    </ul>
			<input type="button" id="create-submit" style="margin-left: 100px" class="btn" value="일정추가"  onclick="schedule_add_action(${emp.empNo})"/>
			<input type="button" id="create-reset" class="btn" value="취소"/>
		</div>
	<table id="schedule_table">
	
	<tr>
		<th></th>
		<c:forEach items="${calendar.weekList }" var="week">
			<th>${week.year }/${week.month + 1}/${week.day }</th>
		</c:forEach>
	</tr>
	<c:forEach var="time" begin="0" end="24">
		<tr>
		<td class="weekly_schedule">${time } : 00</td>
		<c:forEach var="dayOfWeek" begin="0" end="6">
			<td class="weekly_schedule">
				<c:forEach var="work" items="${workList }">
					<c:if test="${calendar.weekList[dayOfWeek].month + 1 == work.workStartTime.getMonth() + 1
						&& calendar.weekList[dayOfWeek].day == work.workStartTime.getDate() 	}">
						<c:if test="${time <= work.workStartTime.getHours() && time + 1 > work.workStartTime.getHours()}">
							<div id="work_title" title="업무일정 / 상태 : ${work.workState} / 담당자 : ${work.name}" onclick="pick_work2(${work.workNo})">${work.workTitle
											}</div>
						</c:if>
					</c:if>
				</c:forEach>
				<c:forEach var="work" items="${workList }">
					<c:if test="${calendar.weekList[dayOfWeek].month + 1 == work.workDeadTime.getMonth() + 1
						&& calendar.weekList[dayOfWeek].day == work.workDeadTime.getDate() 	}">
						<c:if test="${time <= work.workDeadTime.getHours() && time + 1 > work.workDeadTime.getHours()}">
							<div id="work_title_end" title="업무일정 / 상태 : ${work.workState} / 담당자 : ${work.name}" onclick="pick_work2(${work.workNo})">${work.workTitle
											}</div>
						</c:if>
					</c:if>
				</c:forEach>
				<c:forEach var="schedule" items="${scList }">
					<c:if test="${calendar.weekList[dayOfWeek].month + 1 == schedule.scheduleStartDate.getMonth() + 1
						&& calendar.weekList[dayOfWeek].day == schedule.scheduleStartDate.getDate() 	}">
						<c:if test="${time >= schedule.scheduleStartDate.getHours() && time < schedule.scheduleEndDate.getHours()}">
							<div title="개인일정 / 내용 : ${schedule.scheduleContents }" id="schedule_title">${schedule.scheduleTitle}</div>
						</c:if>
					</c:if>
				</c:forEach>
				<c:forEach var="schedule" items="${monthlyList }">
					<c:choose>
								<c:when test="${schedule.monthlyDay != 0}">
									<c:if test="${schedule.monthlyDay == calendar.weekList[dayOfWeek].day }">
										<c:if test="${time >= schedule.startDate.getHours() && time < schedule.endDate.getHours()}">
											<div title="개인일정 / 내용 : ${schedule.scheduleContents }" id="schedule_title_monthly">${schedule.scheduleTitle}//1</div>
											<br>
										</c:if>
									</c:if>
								</c:when>
								<c:otherwise>
									<c:choose>
										<c:when test="${schedule.startDate.getYear() == -1 }">
											<c:if test="${schedule.everyWeekDay == dayOfWeek }">
												<c:if test="${time >= schedule.startDate.getHours() && time < schedule.endDate.getHours()}">
													<div title="개인일정 / 내용 : ${schedule.scheduleContents }" id="schedule_title_monthly">${schedule.scheduleTitle} }</div>
													<br>
												</c:if>
											</c:if>
										</c:when>
										<c:otherwise>
											<c:if test="${calendar.weekList[dayOfWeek].year >= schedule.startDate.getYear() + 1900 && calendar.weekList[dayOfWeek].year <= schedule.endDate.getYear() + 1900}">
												<c:if test="${calendar.weekList[dayOfWeek].month >= schedule.startDate.getMonth() && calendar.weekList[dayOfWeek].month <= schedule.endDate.getMonth() }">
													<c:if test="${calendar.weekList[dayOfWeek].day >= schedule.startDate.getDate() && calendar.weekList[dayOfWeek].day <= schedule.endDate.getDate() }">
														<c:if test="${schedule.everyWeekDay == dayOfWeek }">
															<c:if test="${schedule.startDate.getHours() == time }">
																<div title="개인일정 / 내용 : ${schedule.scheduleContents }" id="schedule_title_monthly">${schedule.scheduleTitle}</div>
																<br>
															</c:if>
														</c:if>
													</c:if>
												</c:if>
											</c:if>
										</c:otherwise>
									</c:choose>
								</c:otherwise>
							</c:choose>
				</c:forEach>
			</td>
		</c:forEach>
		</tr>
	</c:forEach>
	</table>
	</div>
	<script>
		$("input#startDate").datepick({
			dateFormat : 'yyyy-mm-dd'
		});
		$("input#endDate").datepick({
			dateFormat : 'yyyy-mm-dd'
		});
		$(document).ready(function(){
		$('input#create-user').click(buttonClick);
		$('input#create-submit').click(buttonSubmit);
		$('input#create-reset').click(buttonReset);
		});
		
		function buttonClick(){
			$('div#dialog-form').fadeIn("slow");
		}
		function buttonSubmit(){
			$('div#dialog-form').fadeOut("slow");
		}
		function buttonReset(){
			$('div#dialog-form').fadeOut("slow");
		}
		$('span#work_title').tooltip({position:{my:"left+30 center",at:"right top"},
			hide: {effect:"fadeOut", duration:200},
			show: {effect:"fadeIn", duration:200}
			
		});
		$('span#schedule_title').tooltip({position:{my:"left+30 center",at:"right top"},
			hide: {effect:"fadeOut", duration:200},
			show: {effect:"fadeIn", duration:200}
			
		});
	</script>
</div>
<!-- board_contents end div -->
</div>
<!-- board end div  -->